/*
MyOpenLab by Carmelo Salafia www.myopenlab.de
Copyright (C) 2004  Carmelo Salafia cswi@gmx.de

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package VisualLogic;

import java.io.IOException;
import java.io.OutputStream;


class TextAreaStream extends OutputStream
{
    private FrameErrorWarnings frm;
    private StringBuffer buffer = new StringBuffer(1024);
    
    public TextAreaStream(FrameErrorWarnings frm)
    {
        this.frm=frm;
    }
    
    public void write(int b) throws IOException
    {
        if (!frm.isVisible()) frm.setVisible(true);
        
        buffer.append((char)b);
        if (b=='\n')
        {
            frm.jTextArea1.append(buffer.toString());
            buffer.setLength(0);
        }
    }
}

/**
 *
 * @author  Carmelo
 */
public class FrameErrorWarnings extends javax.swing.JFrame
{
    
    /** Creates new form DialogErrorWarnings */
    public FrameErrorWarnings()
    {
        initComponents();
        
        javax.swing.ImageIcon icon =new javax.swing.ImageIcon(getClass().getResource("/Bilder/16x16/process-stop.png"));
        setIconImage(icon.getImage());
        
    }
    
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents()
    {
        jPopupMenu1 = new javax.swing.JPopupMenu();
        jmniClear = new javax.swing.JMenuItem();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        jmniClear.setText("Clear");
        jmniClear.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jmniClearActionPerformed(evt);
            }
        });

        jPopupMenu1.add(jmniClear);

        setTitle("Errors and Warnings");
        jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
        jTextArea1.setColumns(20);
        jTextArea1.setComponentPopupMenu(jPopupMenu1);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
        );
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-332)/2, (screenSize.height-254)/2, 332, 254);
    }// </editor-fold>//GEN-END:initComponents
    
    private void jmniClearActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jmniClearActionPerformed
    {//GEN-HEADEREND:event_jmniClearActionPerformed
        jTextArea1.setText("");
    }//GEN-LAST:event_jmniClearActionPerformed
    
    public void addMessageToConsole(String message)
    {
        jTextArea1.append(message);
        jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
    }
    
    public void clearMessages()
    {
        jTextArea1.setText("");
        
    }
    public String getMessages()
    {
        return jTextArea1.getText();
    }
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTextArea jTextArea1;
    private javax.swing.JMenuItem jmniClear;
    // End of variables declaration//GEN-END:variables
    
}
